//
//  WPHumanPartCell.m
//  wobingwoyi
//
//  Created by WGP on 2016/12/7.
//  Copyright © 2016年 WGP. All rights reserved.
//

#import "WPHumanPartCell.h"
#import "WPHumanPartModel.h"

@interface WPHumanPartCell ()

@end
@implementation WPHumanPartCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier])
    {
        self.backgroundColor = [UIColor clearColor];
        [self partBtn];
    }
    return self;
}

-(UIButton *)partBtn
{
    if(_partBtn == nil)
    {
        _partBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        _partBtn.backgroundColor = [UIColor clearColor];
        [_partBtn addTarget:self action:@selector(partBtnDidClick:) forControlEvents:UIControlEventTouchDown];
        [self.contentView addSubview:_partBtn];
        
        [_partBtn mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.left.equalTo(self.contentView);
            make.right.equalTo(self.contentView).offset(-10);
            make.height.mas_equalTo(35);
        }];
    }
    return _partBtn;
}

-(void)setModel:(WPHumanPartModel *)model
{
    _model = model;
    [self.partBtn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_normal",model.imageName]] forState:UIControlStateNormal];
    [self.partBtn setBackgroundImage:[UIImage imageNamed:[NSString stringWithFormat:@"%@_selected",model.imageName]] forState:UIControlStateSelected];
    self.partBtn.selected = model.isSelected;
}

-(void)partBtnDidClick:(UIButton *)btn
{
    if (self.didSelectedBlock)
    {
        self.didSelectedBlock();
    }
}

@end
